{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-07 10:27:59.763\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-07 10:27:59,900\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-07 10:27:59,902\tINFO worker.py:1582 -- Calling ray.init() again after it has already been called.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21\n",
      "Actor(tech.mlsql.retrieval.RetrievalGateway, 8275f829aa1c778757d937700e000000)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Actor(tech.mlsql.retrieval.RetrievalMaster, 981b8790483cc455c0b85cd70e000000)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "\n",
    "byzerllm.connect_cluster(address=\"auto\",code_search_path=[\"/Users/allwefantasy/.auto-coder/storage/libs/byzer-retrieval-lib-0.1.11\"])\n",
    "\n",
    "retriever = byzerllm.ByzerRetrieval()\n",
    "retriever.launch_gateway()\n",
    "\n",
    "print(retriever.gateway())\n",
    "\n",
    "retriever.cluster(\"byzerai_store\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-07 10:28:37.290\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-07 10:28:37,293\tINFO client_builder.py:244 -- Passing the following kwargs to ray.init() on the server: ignore_reinit_error\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ClientActorHandle(191fce012e919dce504c5b0607000000)\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "ClientActorRef has no attribute 'getCluster'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 10\u001b[0m\n\u001b[1;32m      6\u001b[0m retriever\u001b[38;5;241m.\u001b[39mlaunch_gateway()\n\u001b[1;32m      8\u001b[0m \u001b[38;5;28mprint\u001b[39m(retriever\u001b[38;5;241m.\u001b[39mgateway())\n\u001b[0;32m---> 10\u001b[0m \u001b[43mretriever\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcluster\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbyzerai_store\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/miniconda3/envs/byzerllm/lib/python3.10/site-packages/byzerllm/utils/retrieval/__init__.py:177\u001b[0m, in \u001b[0;36mByzerRetrieval.cluster\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m    174\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclusters:\n\u001b[1;32m    175\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclusters[name]\n\u001b[0;32m--> 177\u001b[0m cluster_ref \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mretrieval_gateway\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgetCluster\u001b[49m\u001b[38;5;241m.\u001b[39mremote(name)\n\u001b[1;32m    178\u001b[0m \u001b[38;5;66;03m# master_ref.buildFromRayObjectStore.remote(\"db1\",\"table1\",data_refs)\u001b[39;00m\n\u001b[1;32m    179\u001b[0m cluster \u001b[38;5;241m=\u001b[39m ray\u001b[38;5;241m.\u001b[39mget(cluster_ref)\n",
      "File \u001b[0;32m/opt/miniconda3/envs/byzerllm/lib/python3.10/site-packages/ray/util/client/common.py:494\u001b[0m, in \u001b[0;36mClientActorHandle.__getattr__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m    492\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init_class_info()\n\u001b[1;32m    493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_method_signatures:\n\u001b[0;32m--> 494\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mClientActorRef has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mkey\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m    495\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ClientRemoteMethod(\n\u001b[1;32m    496\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    497\u001b[0m     key,\n\u001b[1;32m    498\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_method_num_returns\u001b[38;5;241m.\u001b[39mget(key),\n\u001b[1;32m    499\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_method_signatures\u001b[38;5;241m.\u001b[39mget(key),\n\u001b[1;32m    500\u001b[0m )\n",
      "\u001b[0;31mAttributeError\u001b[0m: ClientActorRef has no attribute 'getCluster'"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "\n",
    "byzerllm.connect_cluster(address=\"ray://192.168.3.84:10001\")\n",
    "\n",
    "retriever = byzerllm.ByzerRetrieval()\n",
    "retriever.launch_gateway()\n",
    "\n",
    "print(retriever.gateway())\n",
    "\n",
    "retriever.cluster(\"byzerai_store\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "根据提供的文档，`auto_merge` 参数有两种类型：\n",
      "\n",
      "1. **bool 类型**：如果设置为 `true`，那么等价于 `wholefile`。这意味着生成的代码将完全替换现有的源码文件。\n",
      "\n",
      "2. **字符串类型**：可选值包括：\n",
      "   - `wholefile`：生成的代码将完全替换现有的源码文件。\n",
      "   - `diff`：生成的代码将以差异（diff）的形式合并到现有源码中。\n",
      "   - `strict_diff`：类似于 `diff`，但可能对合并的严格性有更高的要求。\n",
      "\n",
      "这些参数允许用户控制是否以及如何将生成的代码自动合并到现有的源码中。\n"
     ]
    }
   ],
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(api_key=\"xxxx\",base_url=\"http://127.0.0.1:8001/v1\")  \n",
    "\n",
    "response = client.chat.completions.create(\n",
    "                                    messages=[{\n",
    "                                        \"role\": \"user\",\n",
    "                                        \"content\": \"auto_merge 参数有哪些\"\n",
    "                                    }],\n",
    "                                    model=\"xxxx\",                                                   \n",
    "                                )\n",
    "print(response.choices[0].message.content)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
